<template>
  <div class="main-layout">
    <!-- 左侧导航栏 -->
    <div class="sidebar">
      <!-- 微信 logo -->
      <div class="logo">
        <img src="@/assets/vue.svg" alt="微信">
      </div>

      <!-- 导航按钮 -->
      <nav class="nav-menu">
        <router-link 
          v-for="item in navItems"
          :key="item.name"
          :to="{ name: item.routeName }"
          custom
          v-slot="{ navigate, isActive }"
        >
          <button 
            :class="['nav-button', { active: isActive }]"
            @click="navigate"
          >
            <component :is="item.icon" class="icon" />
            <span class="tooltip">{{ item.label }}</span>
          </button>
        </router-link>
      </nav>
    </div>

    <!-- 右侧内容区域 -->
    <div class="content-area">
      <!-- 子路由出口 -->
      <router-view v-slot="{ Component }">
        <transition name="fade" mode="out-in">
          <component :is="Component" />
        </transition>
      </router-view>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useRouter } from 'vue-router'

// 图标导入（示例使用 Element Plus 图标）
import { 
  ChatRound, 
  User, 
  Star, 
  Setting 
} from '@element-plus/icons-vue'

const router = useRouter()

// 导航项配置
const navItems = ref([
  {
    name: 'chat',
    label: '聊天',
    routeName: 'ChatHome',
    icon: ChatRound
  },
  {
    name: 'contacts',
    label: '联系人',
    routeName: 'Contacts',
    icon: User
  },
  {
    name: 'moments',
    label: '朋友圈',
    routeName: 'Moments',
    icon: Star
  },
  {
    name: 'settings',
    label: '设置',
    routeName: 'Settings',
    icon: Setting
  }
])

// 点击导航按钮处理
const handleNavClick = (item) => {
  // 如果是当前已激活路由，可以执行刷新操作
  if (router.currentRoute.value.name === item.routeName) {
    // 执行刷新逻辑（例如重新加载联系人列表）
  }
}
</script>

<style scoped>
.main-layout {
  display: flex;
  height: 100vh;
  background: #f0f0f0;
}

.sidebar {
  width: 80px;
  background: #2e2e2e;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px 0;
}

.logo img {
  width: 40px;
  height: 40px;
  margin-bottom: 30px;
}

.nav-menu {
  display: flex;
  flex-direction: column;
  gap: 15px;
}

.nav-button {
  position: relative;
  width: 50px;
  height: 50px;
  border-radius: 8px;
  border: none;
  background: transparent;
  cursor: pointer;
  transition: all 0.3s;
  color: #fff;

  &:hover {
    background: rgba(255, 255, 255, 0.1);
  }

  &.active {
    background: rgba(0, 122, 255, 0.2);
  }

  .icon {
    width: 24px;
    height: 24px;
  }

  .tooltip {
    visibility: hidden;
    position: absolute;
    left: 60px;
    top: 50%;
    transform: translateY(-50%);
    background: #000;
    color: #fff;
    padding: 6px 12px;
    border-radius: 4px;
    white-space: nowrap;
  }

  &:hover .tooltip {
    visibility: visible;
  }
}

.content-area {
  flex: 1;
  background: #fff;
  border-radius: 8px 0 0 0;
  overflow: hidden;
}

.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.2s;
}

.fade-enter-from,
.fade-leave-to {
  opacity: 0;
}
</style>